package com.dongdongsongcan.app.control;

import com.alibaba.fastjson.JSON;
import com.dongdongsongcan.app.control.bean.OrderDetailData;
import com.dongdongsongcan.app.control.bean.OrderListData;
import com.dongdongsongcan.app.control.bean.OrderStatusData;
import com.dongdongsongcan.app.control.bean.OrderSubmitData;
import com.dongdongsongcan.app.model.api.WebServiceApi;
import com.su.dolphin.control.bean.BaseBean;
import com.su.dolphin.control.task.CtrlTask;
import com.su.dolphin.utils.LogUtil;

/**
 * Created by Administrator on 2015/12/7 0007.
 */
public class OrderControl {

    /**
     * //    "token": "e00cf25ad42683b3df678c61f42c6bda",
     * //            "user_name": "admin",
     * //            "order_louhao1": "\u697c\u53f7",
     * //            "order_name": "\u59d3\u540d",
     * //            "order_sex": "\u7537",
     * //            "order_mobile": "135865478547",
     * //            "order_arrive": "\u5c3d\u5feb\u9001\u5230",
     * //            "order_beta": "\u5907\u6ce8",
     * //            "order_shop_id": "19812",
     * //            "order_pay_method": "afterpayment",
     * //            "order_area_id": "163",
     * order_foods string
     */
    public static void submitOrder(final OrderSubmitData orderSubmitData, CtrlTask.IControlResponse<BaseBean> response) {
        CtrlTask.submitTask(new CtrlTask.IControlWork() {
            @Override
            public BaseBean doWork() {
                orderSubmitData.setToken(UserControl.i().getUser().getToken());
                orderSubmitData.setUser_name(UserControl.i().getUser().getUser_name());
                String orderData = JSON.toJSONString(orderSubmitData);
                return WebServiceApi.order_insert(orderData);
            }
        }, response);
    }

    public static void order_status(final String order_id, CtrlTask.IControlResponse<OrderStatusData> response) {
        CtrlTask.submitTask(new CtrlTask.IControlWork() {
            @Override
            public BaseBean doWork() {
                String userName = "admin";
                return WebServiceApi.order_status(order_id);
            }
        }, response);
    }

    public static void order_info(final String order_id, CtrlTask.IControlResponse<OrderDetailData> response) {
        CtrlTask.submitTask(new CtrlTask.IControlWork() {
            @Override
            public BaseBean doWork() {
                String userName = "admin";
                return WebServiceApi.orderInfo(order_id);
            }
        }, response);
    }

    /**
     * today,month ,previous
     *
     * @param response
     */
    public static void getOrders(final String date, final int offset, final int pagesize, CtrlTask.IControlResponse<OrderListData> response) {
        CtrlTask.submitTask(new CtrlTask.IControlWork() {
            @Override
            public BaseBean doWork() {
                return WebServiceApi.order(date, offset, pagesize);
            }
        }, response);
    }
}
